package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.BillInRecordDto;
import com.deer.wms.base.system.model.box.BoxItemDto;
import com.deer.wms.base.system.model.box.StockOverViewDo;
import com.deer.wms.base.system.model.box.StockOverviewDto;
import com.deer.wms.base.system.model.item.ItemInfoDto;
import com.deer.wms.base.system.service.box.IBoxItemService;
import com.deer.wms.base.system.service.item.IItemInfoService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 库存总览Controller
 * @author 申紫微
 * @version 1.0
 * @description
 * @data 2020-10-09 10:17:47
 */
@Controller
@RequestMapping("/stockOverview")
public class StockOverviewController extends BaseController {

    @Autowired
    private IBoxItemService boxItemService;
    @Autowired
    private IItemInfoService itemInfoService;

    private String prefix = "stockOverview";

    @RequiresPermissions("stockOverview:view")
    @GetMapping
    public String stockOverview(Model model){
        List<String> name = itemInfoService.findName();
        model.addAttribute("itemName",name);
        return prefix + "/stockOverview";
    }

    /**
     * 查询库存总览
     * @author 申紫微
     * @date 11:08 2020/10/9
     * @params stockOverviewDto
     * @return com.deer.wms.common.core.page.TableDataInfo
     **/
    @RequiresPermissions("stockOverview:list")
    @RequestMapping("findList")
    @ResponseBody
    public TableDataInfo findStockOverviewList(StockOverviewDto stockOverviewDto){
        startPage();
        List<StockOverviewDto> list =  boxItemService.findStockOverviewList(stockOverviewDto);
        return getDataTable(list);
    }

    /**
     * 库存总览导出
     * @return
     */
    @RequiresPermissions("stockOverview:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(){
        List<StockOverViewDo> list = boxItemService.findExportList();
        ExcelUtil<StockOverViewDo> util = new ExcelUtil<StockOverViewDo>(StockOverViewDo.class);
        return util.exportExcel(list, "库存总览");
    }

}

